cmode

The cmode command allows you to go in the C-calculator mode. The only way to come back to the main fitting mode is by using the fmode command or to type ˆ D in interactive mode. Commands cannot be abbreviated in cmode. Parallel to the cmode command, the let command can be used to pass one single command, or command line to mathematical parser. To be consistent with pmode command, cmode also accepts arguments in which case it is equivalent to the let command. It is not an error to call cmode from the C-calculator mode. A warning message will be given though.

cmode command-list

The C-calculator mode supports most of C syntax (see item C), and most of the C math library. Thus, the following functions are supported:

    trigo:    hyperbolic:  expo:    special:   conversion:  random:

    cos()     cosh()       ln()      besy0()    trunc()     srand()
    cot()     coth()       log()     besy1()    floor()     rand()
    csc()     csch()       exp()     besj0()    ceil()
    sec()     sech()       sqrt()    besj1()    rint()
    sin()     sinh()       cbrt()    besjn()    abs()
    tan()     tanh()                 besyn()    int()
    acos()   acosh()                 erf()      scan()
    asin()   asinh()                 erfc()     min()
    atan()   atanh()                 lgamma()   max()
    atan2()                          interp()   sum()
                                                vread()

Any upper case variable (possibly including `_') possibly mixed with digits will be recognized as a vector, e.g., TEMP_2, TEST, D, etc. Any lower case name will be taken as a scalar variable, e.g., x, t4, etc. There are two predefined constants, pi = π and e= e, which should not be unlocked and modified. As well, the built-in constant data contains the current size of the vectors and can be modified through the set data command, by the read/exec commands, or by unlocking the constant and modifying it directly. The built-in constant chi2 contains the value of χ2 as obtained from the latest fit. And finally, the built-in scalar constant param contains the number of parameters as defined by set parameters.

A mix of upper case and lower case letters will serve to indicate a string variable. Strings values are indicated by double quotes as in C. Unlike C, considers strings as self-contained objects that can be added, subtracted, and checked for (in)equality. Thus, string objects (i.e. string variables, string constants and string values) can: serve as argument to scan function; be part of string assignment statements or of a truth statement involving (in)equality operator; be added (concatenated using the `+' operator) one with another; be subtracted (remove string termination using the `-' operator) one with another; and finally be argument of string functions.

A predefined string constant called Tmp contains the string "/tmp/fudgitPID" where PID is the process id number of the current process. This file, and any file belonging to you, whose name starts with the same string, will be erased automatically by the exit or quit commands. This string is typically used by the gnuplot macro in order to pass data to the plotting program which cannot read data from standard input. Another predefined string constant is ReadFile which contains the last data filename that has been loaded. Finally, the string constant Cwd is made available in order to get the current working directory.

The following table contains all the built-in constants.

    chi2               Value of chi^2 from the last fit;
    data               Length of all vectors (< samples) as set by set data;
    e                  Neperian number;
    param              Number of parameters as set by set parameters;
    pi                 Guess this one;

    Cwd                Current working directory;
    ReadFile           The last file (program) read by read (exec);
    Tmp                A temporary filename "/tmp/fudgitPID";

Constants (either strings and scalars) can also be created by locking a variable. In the same manner, a constant can be modified directly if it has been unlocked.

The algebraic operations applicable to scalar variables can be applied to vectors. Vector algebra can be mixed with scalar variable algebra in which case the user has to take the implied loop into account. For example, although the following operation is not standard C programming: [*]

     cmode
         x = 0
         X = x++
will define a vector X of size data (see set data) ranging from X[1] to X[data] and taking values from 0 to data - 1. Multiple commands can be given with the separator `;', for example, another version of the previous command could be written
     cmode
         x=0;X=++x
in which case a vector X taking values from 1 to data will be created. (Note that the latter uses a pre-increment whereas the former uses a post-increment operator on x: results are thus different). Vector elements can be referenced by elements using standard C grammar. Therefore, the same vector could be created by using a while construction as in:
     fmode
     set data 1000
     let X=0;i=0
     cmode
         while (i++ <= data)
            X[i] = i
     fmode
or, using a for loop,
     cmode
        for (x=0;x<=data;x++) {
            X[x] = x
        }
     fmode

Noninteger variables will be truncated to the nearest lower integer to form a vector index.

     cmode
         y= 2.01
         x=2.23; X[2]=Z[y]+5^x

Assigning a vector to a constant will assign all the elements to that constant.

     fmode
     let X = pi
     let Z2 = 0

The C-calculator checks for undefined variables on the RHS of any assignment. From C-calculator mode, variables values can be seen by typing the variable name by itself or by using the print command, if the output is selected to be stdout. From the fitting mode, contents of constants and variables (either strings or scalars) is displayed using show variables command, or by using the `$' expansion operator. However, vectors can be only be seen from the fitting mode by using the show vector command.

Each unknown vector name given on the command line allocates a vector of sample size.

To be a calculator as such, the C-calculator prints the value of the expression given on the command line. Thus, the statement

     cmode
         x + 2
will print the value of x + 2.0. The contents of many variables can be displayed at the same time by giving a coma separated list such as in
     cmode
         x,"temperature", t
where the string temperature will be printed between the values of variables x and t. Note that the C-calculator mode recognizes strings by double quotes. Special characters such as '\n' are also legal in a string.

We conclude by giving some examples involving string variables:

     fmode
     let String = "new.file"
     let x = (String == "new.file")
     let y = ("file1" == "file2")
     let Bing = "\a\a\a"
     let Here = Cwd        # Store the value of the current working directory
     let Input = Read()                       # Read from stdin
     let Test = FileName(ReadFile) - ".data"
     let Dir = DirName(InputFile)
     let y = scan(Read(), "%lf")
     let File = "STRING_23.4"
     let number = scan("%*[_A-Z]%lf", File)
     let Message = "A tab \t and a newline\n"
where the truth statement could be legally used as a condition for an if, a while, or a for.

let, C, data, func, proc, print, fmode, math, while, for, return,
auto, if, break, samples, quotes, strings